package com.ruoyi.web.controller.vpn.cilent;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.vpnClient.domain.Disconnect;
import com.ruoyi.vpnClient.service.ClientService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Anonymous
@RequestMapping("/client")
public class Cilent extends BaseController {
    @Resource
    ClientService clientService;

    /**
     * openvpn连接时调用此方法 判断师傅可以连接
     * @param username
     * @param password
     * @return
     */
    @GetMapping("isok")
    public AjaxResult isOK(@RequestParam(required = false) String username,@RequestParam(required = false) String password){
        System.out.println("username = " + username);
        System.out.println("password = " + password);

       boolean flag =  clientService.isOK(username,password);
       if (flag){
           return  success();
       }
       return error();

    }

    /**
     * openvpn断开时调用此方法 对流量进行扣除
     * @param disconnect
     * @return
     */
    @GetMapping("disconnect")
    public  AjaxResult disconnect(Disconnect disconnect){

        System.out.println(disconnect);
        clientService.discount(disconnect);

        return success();
    }



}
